﻿using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using MPBlog.DAL;

namespace MPBlog.Core
{
    /// <summary>
    /// 所有母版页的基类
    /// 1.提供公用js文件，如jquery 和 mpblogcore.js的引用
    /// </summary>
    public class MasterBase : MasterPage
    {
        #region - controls define -

        protected System.Web.UI.WebControls.Repeater RptMenu;

        #endregion

        #region - property -

        #endregion

        readonly MenuDao menu = new MenuDao();


        protected override void OnLoad(EventArgs e)
        {
            //AddCommonJs("Scripts/jquery-1.4.1.min.js");
            //AddCommonJs("Scripts/MPBlogCore.js");

            if (RptMenu != null)
            {
                RptMenu.DataSource = menu.GetList();
                RptMenu.DataBind();
            }
            base.OnLoad(e);
        }

        /// <summary>
        /// 添加通用的js文件，相对于网站根目录
        /// </summary>
        private void AddCommonJs(string jsFilePath)
        {
            HtmlGenericControl myJs = new HtmlGenericControl();
            myJs.TagName = "script";
            myJs.Attributes.Add("type", "text/javascript");
            myJs.Attributes.Add("src",Utils.AbsoluteWebRoot+ jsFilePath);
            Page.Header.Controls.Add(myJs);
        }


        /// <summary>
        /// 获得Admin下的主题文件夹的绝对路径，以/结尾
        /// </summary>
        protected string RootAdminTheme(string themeName)
        {
            return Utils.AbsoluteWebRoot + "Admin/Themes/" + themeName + "/";
        }

        /// <summary>
        /// 获得前台主题文件夹的绝对路径，以/结尾
        /// </summary>
        protected string RootTheme(string themeName)
        {
            return Utils.AbsoluteWebRoot + "Themes/" + themeName + "/";
        }

        /// <summary>
        /// 返回admin文件夹的绝对地址
        /// </summary>
        /// <returns></returns>
        public string RootAdmin()
        {
            return Utils.AbsoluteWebRoot + "Admin/";
        }

        /// <summary>
        /// 返回网站根目录的绝对路径,以/结尾
        /// </summary>
        /// <returns></returns>
        public string Root()
        {
            return Utils.AbsoluteWebRoot.AbsolutePath;
        }

    }
}
